package com.big.pay.listener;

import com.alibaba.fastjson.JSON;
import com.big.common.result.Result;
import com.big.common.utils.JsonUtils;
import com.big.model.model.order.MerchandiseOrder;
import com.big.model.model.patient.PatientInfo;
import com.big.model.model.patient.address.PatientAddress;
import com.big.model.model.pay.PayLog;
import com.big.model.vo.sms.PaySmsVo;
import com.big.order.OrderFeignClient;
import com.big.patient.PatientFeignClient;
import com.big.pay.config.RabbitConfig;
import com.big.pay.service.PayLogService;
import com.big.sms.SmsFeignClient;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SmsListener {

    @Autowired
    OrderFeignClient orderFeignClient;

    @Autowired
    SmsFeignClient smsFeignClient;

    @Autowired
    PatientFeignClient patientFeignClient;

    //监听短信
    @RabbitListener(queues = RabbitConfig.QUEUE_MSM_ITEM)
    public void onPay(String oId, Channel channel , Message message){
      log.info("值:{}",oId);

      Result order = orderFeignClient.findOrder(oId);
      System.out.println(order);
      //订单信息
      MerchandiseOrder merchandiseOrder = JsonUtils.JSONStringInfoTurnClass(JSON.toJSONString(order.getData()), MerchandiseOrder.class);
      //用户信息 获取手机号
      PatientInfo userById = patientFeignClient.findUserById(String.valueOf(merchandiseOrder.getPId()));
      PaySmsVo paySmsVo=new PaySmsVo();
      paySmsVo.setDid(merchandiseOrder.getDId());
      paySmsVo.setMobile(userById.getPhone());
      paySmsVo.setTotalMoney(merchandiseOrder.getDTotal());
      paySmsVo.setWeb("测试网站集群1");
      smsFeignClient.PaySend(paySmsVo);
    }




}
